package org.hot100_1;

import org.leetcode.middle.leetcode138.Node;

import java.util.HashMap;
import java.util.Map;

public class leetcode32 {
    public Node copyRandomList(Node head) {

        if (head==null){
            return head;
        }

        Map<Node,Node> map = new HashMap<>();

        Node node = head;

        while (node!=null){
            map.put(node,new Node(node.val));
            node=node.next;
        }

        node=head;

        while (node!=null){
            Node copyNode = map.get(node);
            copyNode.next=map.get(node.next);
            copyNode.random=map.get(node.random);
            node=node.next;
        }
        return map.get(head);
    }
}
